package property.personal.property_mange.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import property.personal.property_mange.pojo.Propertyinfo;

import java.util.List;

@Repository
@Mapper
public interface PagingMapper extends BaseMapper<Propertyinfo> {

    @Select("select count(id) as pagecount from propertyinfo")
    @Results({
            @Result(property = "pagecount" ,column = "pagecount")
    })
    int getpagecount();

    @Select("select id,property_name,property_code,director,telphone,login_password,property_address,property_indroduce,status from propertyinfo where property_name like '%${property_name}%' limit #{begin},#{pagesize}")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "property_name",column = "property_name"),
            @Result(property = "property_code",column = "property_code"),
            @Result(property = "director",column = "director"),
            @Result(property = "telphone",column = "telphone"),
            @Result(property = "login_password",column = "login_password"),
            @Result(property = "property_address",column = "property_address"),
            @Result(property = "property_indroduce",column = "property_indroduce"),
            @Result(property = "status",column = "status")
    })
    List<Propertyinfo> search(String property_name, int begin, int pagesize);

    @Update("update propertyinfo set status=#{status} where id=#{id}")
    int updatebyid(int id,String status);



    @Select("select id,property_name,property_code,director,telphone,login_password,property_address,property_indroduce,status,property_logo from propertyinfo limit #{begin},#{pagesize}")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "property_name",column = "property_name"),
            @Result(property = "property_code",column = "property_code"),
            @Result(property = "director",column = "director"),
            @Result(property = "telphone",column = "telphone"),
            @Result(property = "login_password",column = "login_password"),
            @Result(property = "property_address",column = "property_address"),
            @Result(property = "property_indroduce",column = "property_indroduce"),
            @Result(property = "status",column = "status"),
            @Result(property = "property_logo",column = "property_logo")
    })
    List<Propertyinfo> getproperty_one(int begin, int pagesize);

    @Update("update propertyinfo set ${columname}=#{value} where id=#{id}")
    int updateby(String columname,Object value,int id);

    @Select("select id,property_name,property_code,director,telphone,login_password,property_address,property_indroduce,status,property_logo from propertyinfo where property_name like '%${property_name}%' limit #{begin},#{pagesize}")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "property_name",column = "property_name"),
            @Result(property = "property_code",column = "property_code"),
            @Result(property = "director",column = "director"),
            @Result(property = "telphone",column = "telphone"),
            @Result(property = "login_password",column = "login_password"),
            @Result(property = "property_address",column = "property_address"),
            @Result(property = "property_indroduce",column = "property_indroduce"),
            @Result(property = "status",column = "status"),
            @Result(property = "property_logo",column = "property_logo")
    })
    List<Propertyinfo> getdatasearch(String property_name, int begin, int pagesize);

    @Select("select count(id) as pagecount from propertyinfo where property_name like '%${property_name}%' ")
    @Results({
            @Result(property = "pagecount" ,column = "pagecount")
    })
    int getsearchcount(String property_name);

    @Select("select id,property_name,property_code,director,telphone,login_password,property_address,property_indroduce,status,property_logo from (select * from propertyinfo limit #{begin},#{pagesize}) temp ORDER by ${colum} ${order}")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "property_name",column = "property_name"),
            @Result(property = "property_code",column = "property_code"),
            @Result(property = "director",column = "director"),
            @Result(property = "telphone",column = "telphone"),
            @Result(property = "login_password",column = "login_password"),
            @Result(property = "property_address",column = "property_address"),
            @Result(property = "property_indroduce",column = "property_indroduce"),
            @Result(property = "status",column = "status"),
            @Result(property = "property_logo",column = "property_logo")
    })
    List<Propertyinfo> orderby(int begin, int pagesize, String colum, String order);

    @Select("select id,property_name,property_code,director,telphone,login_password,property_address,property_indroduce,status,property_logo from \n" +
            "(select * from propertyinfo where property_name like '%${property_name}%' limit #{begin},#{pagesize}) temp ORDER BY ${colum} ${order}")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "property_name",column = "property_name"),
            @Result(property = "property_code",column = "property_code"),
            @Result(property = "director",column = "director"),
            @Result(property = "telphone",column = "telphone"),
            @Result(property = "login_password",column = "login_password"),
            @Result(property = "property_address",column = "property_address"),
            @Result(property = "property_indroduce",column = "property_indroduce"),
            @Result(property = "status",column = "status"),
            @Result(property = "property_logo",column = "property_logo")
    })
    List<Propertyinfo> searchorderby(String property_name, int begin, int pagesize, String colum, String order);


}
